import { useState } from 'react';
import { PaginationResponse } from '@datorama/akita';

import { makeFacade, RoomsFacade } from '@/facade/roomEntityFacade';
import { VISIBILITY_FILTER } from '@/models/commonType';
import { useObservable } from '@/utils/rxHelpers';
import { RoomItem } from '@/models/response/roomRsp';

export type RoomsHookTuple = [RoomsFacade, PaginationResponse<RoomItem>, VISIBILITY_FILTER];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useRoomsFacade(statType?: number): RoomsHookTuple {
  const [roomsFacade] = useState(() => makeFacade(statType || 0)); //默认返回访问过的房间列表
  
  const [filter] = useObservable(roomsFacade.filter$, VISIBILITY_FILTER.SHOW_ALL);
  const [pagination] = useObservable(roomsFacade.pagination$, {} as PaginationResponse<RoomItem>);

  return [roomsFacade, pagination, filter];
}
